package demo1;

/**
 * Created with IntelliJ IDEA.
 * User: 12629
 * Date: 2022/2/24
 * Time: 20:27
 * Description:
 */
class Shape {
    public void draw() {
        //System.out.println("这是画图形的方法！");
    }
}
class Cycle extends Shape {
    @Override
    public void draw() {
        System.out.println("画●！");
    }
}
class Rect extends Shape {
    @Override
    public void draw() {
        System.out.println("画♦！");
    }
}
class Flower extends Shape{
    @Override
    public void draw() {
        System.out.println("画❀！");
    }
}
class Triangle extends Shape {
    @Override
    public void draw() {
        System.out.println("画△！");
    }
}
public class TestDemo2 {

    public static void drawMap(Shape shape) {
        shape.draw();
    }

    public static void main(String[] args) {
        Cycle cycle = new Cycle();
        drawMap(cycle);
        drawMap(new Rect());
        drawMap(new Flower());
        drawMap(new Triangle());
    }

    public static void drawShapes() {
        Rect rect = new Rect();
        Cycle cycle = new Cycle();
        Flower flower = new Flower();
        String[] shapes = {"圆圈", "rect", "圆圈", "rect", "flower"};
        //代码非常搓   根据不同情况去区分  看起来太笨拙了
        for (String shape : shapes) {
            if (shape.equals("圆圈")) {
                cycle.draw();
            } else if (shape.equals("rect")) {
                rect.draw();
            } else if (shape.equals("flower")) {
                flower.draw();
            }
        }
    }

    public static void main2(String[] args) {
        drawShapes();
    }

}
